<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src=" https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
</head>
<style>
    li{
        list-style: none;
        float: left;
        margin: 0 10px;
        border: 1px solid;
    }
</style>
<body>
    <!-- 购物车实现 -->
    <lable><input name="fruits" type="checkbox">apple-<span>10</span></lable>
        <button>+</button><input name="num" type="text" value="0"
        style="width: 15px;"><input name="jian" type="button" value="-">
        <br>
        <lable><input name="fruits" type="checkbox">香梨-<span>15</span></lable>
        <button>+</button><input name="num" type="text" value="0"
        style="width: 15px;"><input name="jian" type="button" value="-">
        <br>
        <lable><input name="fruits" type="checkbox">火腿肠-<span>56</span></lable>
        <button>+</button><input name="num" type="text" value="0"
        style="width: 15px;"><input name="jian" type="button" value="-">
        <br>
        <lable><input name="fruits" type="checkbox">中华烟-<span>70</span></lable>
        <button>+</button><input name="num" type="text" value="0"
        style="width: 15px;"><input name="jian" type="button" value="-">
        <br>
        <h2>总价:<i>0</i></h2>
        全选/反选: <input type="checkbox" name="" id="all">
</body>
<script>
    //购物车实现
    $(function(){
        $("[name='fruits'],[name='num']").change(function(){
            var sum=0
            $("[name='fruits']").each(function(index){
                if($(this).prop('checked')==true){
                    sum+=(+$(this).next().html())*(+$(this).parent().next().next().val())
                }
            })
            $('i').html(sum)
        })
        $('button').click(function(){
            $(this).next().val(+$(this).next().val()+1)
            $(this).next().removeAttr('disabled')
            $(this).next().next().removeAttr('disabled')
            $("[name='num']").change()
        })
        $("[name='jian']").click(function(){
            if((+$(this).prev().val())<1){
                $(this).attr('disabled',true)
                $(this).prev().attr('disabled',true)
                return;
            }
            $(this).prev().val((+$(this).prev().val())-1)
            $("[name='num']").change()
        })
        $('#all').change(function(){
            $("[name='fruits']").prop('checked',$(this).prop('checked'))
            $("[name='num']").change()
        })
    })


  
</script>
</html>